%% The 'switch-case' control structure

%This is useful when selecting an action based on a string input

S='Exp32' %This is the input string

switch S %Decide what to do based on 'S'
    case 'Exp1' %if 'S' matches this, do this case
        fprintf('Exp1\n')
    case 'Exp32' %if 'S' matches this, do this case
        fprintf('Exp32\n')
    otherwise %No matches to 'S', do this case
    fprintf('Didn''t find matching case.\n')
end

%We can also use the 'switch-case' for other variable types:

X=3 %This is the input string

switch X %Decide what to do based on 'S'
    case 0 %if X==0
        fprintf('X=0\n')
    case 3 %if X==3
        fprintf('X=3\n')
    otherwise %No matches to X, do this case
    fprintf('Didn''t find matching case.\n')
end

%doc switch


%% Basic Array Operations

%sum():   Add numbers in array
%mean():  Mean of array elements
%std():   Standard Deviation of array elements
%var():   Variance of array elements

%come others: max,min,mode,median

%Generate an array of random numbers selected from the uniform distribution
A=rand(4,5)

%Find the mean of each column of A 
mean(A)

%This is the same as:
mean(A,1)

%Find the mean of each row of A 
mean(A,2)

%Find the mean of all elements. Any of these works:

mean(mean(A,2))
mean(mean(A,1))
mean(A(:))

%The various functions mentioned above operate on the data the same way
sum(A,2)
std(A)
var(A)
median(A)
mode(A)


%%  Cell Arrays

%Useful for holding data of differing sizes or data types
%doc cell

%Cell Arrays- Note the indexing with '{}'

%Add elements to the cell array. 'CellEx' could be any MATLAB variable
%name. 
CellEx{1}='Data Set 1'
CellEx{2}=rand(4,1)
CellEx{3}=rand(5,2)

%Get back the contents of a cell. 
S1=CellEx{1}



%% Structures

%doc struct

%Useful for organizing data with descriptive 'field' names

%Add or set fields to a structure. These can be any data type
SrtEx.Date='2-3-16'
SrtEx.Data=rand(6,1)
SrtEx.LaserPower=5
SrtEx.OurFunc = @(x)x.^2

%Get back the fields
SrtEx.Data
SrtEx.OurFunc(3)

%% Classes and Objects

%The most basic thing we can do with a class is to use it like a structure,
%that has fixed fields. 

%See 'ExpContainer.m'

%Create a variable of type 'ExpContainer'
%We can also say we create an 'object' from class 'ExpContainer'
ExpC1 = ExpContainer()

%In a class/object these are called 'Properties':

%Set Property values
ExpC1.Date='2-3-16'
ExpC1.Data=rand(8,1)
ExpC1.OurFunc = @(x)x.^2

%Trye to set an non-existing property
ExpC1.Data33=4

%Get back a property
ExpC1.Date

%Create a new object
ExpC2=ExpContainer()







